import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

//使用数组实现栈
public class MyStack {
    private int Default = 10;
    public int[] arr = new int[Default];
    public int size;
    public int top;
    public int now;

    public void push(int val) {
        isFull();
        arr[top++] = val;
        now = top - 1;
        size++;
    }

    public int pop() {
        if (isEmpty()) {
            throw new RuntimeException("空了");
        }
        size--;
        top--;
        return arr[now--];
    }

    public int peek() {
        return arr[now];
    }

    private void isFull() {
        if (size == Default) {
            this.arr = Arrays.copyOf(arr, 2 * Default);
            Default *= 2;
        }
    }

    public Boolean isEmpty() {
        return size == 0;
    }
}
class text11 {
    public static void main(String[] args) {
        Stack<Integer> hh = new Stack<>();
        hh.push(1);
        hh.pop();
        hh.peek();
        hh.isEmpty();
        Queue<Integer> hhh = new LinkedList<>() {};
    }
    public static void main5(String[] args) {
        Stack hhh = new Stack();

        MyStack hh = new MyStack();
        hh.push(1);
        hh.push(2);
        hh.push(3);
        hh.push(4);
        System.out.println(hh.pop());
        hh.push(5);
        System.out.println(hh.pop());
        hh.push(6);
        System.out.println("end");
    }
    public static void main2(String[] args) {
        MyStack wow = new MyStack();
        System.out.println(wow.size);
    }
    public static void maina(String[] args) {
        MyStack wow = new MyStack();
        for (int i = 0; i < 11; i++) {
            wow.push(i);
        }
        for (int i = 0; i < 11; i++) {
            System.out.print(wow.peek() + " ");
            wow.pop();
        }
        System.out.println();
        System.out.println(wow.isEmpty());
    }
}
